import React from 'react'
import { Layout,Image} from 'antd';
import Table from '../Table'
import Editor from "../Editor"
import "./tr.css"
import {useSelector,useDispatch,connect} from 'react-redux'

const {Content} = Layout;

const Score = () => {
  const scoreList = useSelector(state=> state.score.scoreList)
  const valueList = useSelector(state=> state.value.valueList)
  const dispatch = useDispatch()
  const columns = [
    {
      title: '学校名称',
      key: 'school_name',
      dataIndex: 'school_name',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '城市',
      key: 'school_city',
      dataIndex: 'school_city',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '考试年份',
      key: 'exam_year',
      dataIndex: 'exam_year',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '政治',
      key: 'politics_score',
      dataIndex: 'politics_score',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '英语',
      key: 'english_score',
      dataIndex: 'english_score',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '专业课一',
      key: 'major_score1',
      dataIndex: 'major_score1',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '专业课二',
      key: 'major_score2',
      dataIndex: 'major_score2',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '总分',
      key: 'whole_score',
      dataIndex: 'whole_score',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '复试',
      key: 'reexam',
      dataIndex: 'reexam',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '录取分数',
      key: 'admit_score',
      dataIndex: 'admit_score',
      valueType: 'text',
      ellipsis:true
    },
    {
        title: '操作',
        key: 'option',
        width: 120,
        valueType: 'option',
        render: (text,record,index,action) => [<div onClick={()=>{
          dispatch({type:'get',con:record});console.log(valueList)
        }}><Editor ques={interest} url='http://101.34.58.111:8081/schoolscore'/></div>
        , <a onClick={async ()=>{
          console.log(record)
          await fetch(`http://101.34.58.111:8081/schoolscore/${record.school_name}/${record.exam_year}`,{
          method:'delete',
          headers: {
            'Content-Type': 'application/json;charset=UTF-8'
          }
        })
        dispatch({type:'delete',content:['delete']})
        }}>删除</a>]
      }];

    const right = {}

    const interest = [
      {name:'school_name',label:'学校名称',tooltip:'最长为24位',placeholder:'输入学校名称'},
      {name:'school_city',label:'学校地点',tooltip:'最长为24位',placeholder:'请输入学校地点'},
      {name:'exam_year',label:'考试年份',tooltip:'最长为24位',placeholder:'输入年份'},
      {name:'politics_score',label:'政治',placeholder:'输入政治'},
      {name:'english_score',label:'英语',placeholder:'输入英语'},
      {name:'major_score1',label:'专业课一',placeholder:'请输入专业课一'},
      {name:'major_score2',label:'专业课二',placeholder:'请输入专业课二'},
      {name:'whole_score',label:'总分',placeholder:'请输入总分'},
      {name:'reexam',label:'复试',placeholder:'请输入复试'},
      {name:'admit_score',label:'录取分数',placeholder:'请输入录取分数'}
    ]

    return (
        <Content className="site-layout-background" style={{paddingLeft: 10,margin: 0,minHeight: 280}}>
          <Table title="学校分数线管理" columns={columns} right={right} url="http://101.34.58.111:8081/schoolscore" ques={interest}/>
        </Content>
    )
}

export default connect()(Score)
